home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Applications / MacGS 2.5.2ß3 / (MacGSLib.π) / gp_mac.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-04-17  |  15.7 KB  |  870 lines  |  [TEXT/R*ch]

  1. /* Copyright (C) 1989, 1990, 1991 Aladdin Enterprises.  All rights reserved.
  2.    Distributed by Free Software Foundation, Inc.
  3.  
  4. This file is part of Ghostscript.
  5.  
  6. Ghostscript is distributed in the hope that it will be useful, but
  7. WITHOUT ANY WARRANTY.  No author or distributor accepts responsibility
  8. to anyone for the consequences of using it or for whether it serves any
  9. particular purpose or works at all, unless he says so in writing.  Refer
  10. to the Ghostscript General Public License for full details.
  11.  
  12. Everyone is granted permission to copy, modify and redistribute
  13. Ghostscript, but only under the conditions described in the Ghostscript
  14. General Public License.  A copy of this license is supposed to have been
  15. given to you along with Ghostscript so you can know your rights and
  16. responsibilities.  It should be in a file named COPYING.  Among other
  17. things, the copyright notice and this notice must be preserved on all
  18. copies.  */
  19.  
  20. /* gp_mac.c */
  21. /* Macintosh-specific routines for Ghostscript */
  22.  
  23. #include <GestaltEqu.h>
  24. #include <Traps.h>
  25. #include "memory_.h"
  26. #include "string_.h"
  27. #include "gx.h"
  28. #include "gp.h"
  29. #include "gserrors.h"
  30. #include "gmacprefs.h"
  31. #include <console.h>
  32.  
  33.  
  34. /* Globals */
  35.  
  36. Boolean        gWNEPresent;        //    WaitNextEvent present
  37. Boolean        gHasColorQD;        //    32-Bit QD present
  38. Boolean        gSys7SFDlog;        //    System 7 SF Dialog present
  39. Boolean        gHasFindFolder;        //    System 7 FindFolder present
  40. WindowPtr    gConsoleWinPtr;        //    console window pointer
  41. Point        gSFWhere = {-1, -1};
  42. char        gSFFName[32];
  43.  
  44.  
  45. /* Do platform-dependent initialization */
  46.  
  47.     void
  48. gp_init (void)
  49.  
  50. {
  51.     extern char    *gs_lib_default_path;
  52.     extern char    *gs_init_file;
  53.     Str255            string;
  54.     MacPrefsH        hPrefs = (MacPrefsH) GetResource (MACPREFS_RES_TYPE, MACPREFS_RES_ID);
  55.     char            fFlags = 0;
  56. #ifdef __GS_ARGC_ARGV__
  57.     int                 argc;
  58.     char          **argv;
  59. #endif
  60.     void            InitGlobals (void);
  61.     void            gp_macui_open (void);
  62.  
  63.  
  64.     SetCurrentA5 ();
  65.     InitGlobals ();
  66.  
  67.     GetIndString (string, MACSTRS_RES_ID, iConsoleWinTitleStr);
  68.  
  69.     if (ResError () == noErr)
  70.     {
  71.         char   *pStr = gs_malloc (1, (size_t) (string[0] + 1), "gp_init");
  72.  
  73.  
  74.         BlockMove ((Ptr) string, (Ptr) pStr, (Size) (string[0] + 1));
  75.  
  76.         console_options.title = (unsigned char *) pStr;
  77.     }
  78.  
  79.     console_options.pause_atexit = 0;
  80.  
  81.     if (hPrefs /* != (MacPrefsH) NULL */)
  82.     {
  83.         fFlags = (*hPrefs)->flags;
  84.  
  85.         if (fFlags & iUseConsRes)
  86.         {
  87.             console_options.nrows = (*hPrefs)->consoleRows;
  88.             console_options.ncols = (*hPrefs)->consoleCols;
  89.         }
  90.  
  91.         if (fFlags & iExitPause)
  92.             console_options.pause_atexit = 1;
  93.  
  94.         ReleaseResource ((Handle) hPrefs);
  95.     }
  96.  
  97.     __open_std ();
  98.     gConsoleWinPtr = FrontWindow ();
  99.  
  100. #ifdef __GS_ARGC_ARGV__
  101.     if (fFlags & iUseCLI)
  102.         argc = ccommand (&argv);
  103. #endif
  104.  
  105.     /*...Initialize Ghostscript's default library paths and initialization file...*/
  106.  
  107.     {
  108.         int            i;
  109.         char      **p;
  110.  
  111.  
  112.         for (i = iGSLibPathStr, p = &gs_lib_default_path;
  113.              i <= iGSInitFileStr;
  114.              i++, p = &gs_init_file)
  115.         {
  116.             GetIndString (string, MACSTRS_RES_ID, i);
  117.             (void) PtoCstr (string);
  118.             *p = gs_malloc (1, (size_t) (strlen ((char *) string) + 1), "gp_init");
  119.             strcpy (*p, (char *) string);
  120.         }
  121.     }
  122.  
  123.     gp_macui_open ();
  124. }
  125.  
  126.  
  127. /* Do platform-dependent cleanup. */
  128.  
  129. /* It sure would be nice if Peter changed gp_finit () to have the exit
  130.  * code as its formal parameter and pass the code down to this routine.
  131.  * This would allow gp_exit () to change console.pause_at_exit if
  132.  * something untoward happened during execution; otherwise we *might*
  133.  * lose germane error messages if the console window is summarily destroyed.
  134.  */
  135.  
  136.     void
  137. gp_exit (void)
  138.  
  139. {
  140. }
  141.  
  142.  
  143. /* Read the current date (in days since Jan. 1, 1980) */
  144. /* and time (in milliseconds since midnight). */
  145.  
  146.     void
  147. gp_get_clock (long *pdt)
  148.  
  149. {
  150.     long                secs;
  151.     DateTimeRec            dateRec;
  152.     static DateTimeRec    baseDateRec = {1980, 1, 1, 0, 0, 0, 1};
  153.     long                pdtmp[2];
  154.     void                 do_get_clock (DateTimeRec *dateRec, long *pdt);
  155.  
  156.  
  157.     GetDateTime ((unsigned long *) &secs);
  158.     Secs2Date (secs, &dateRec);
  159.  
  160.     do_get_clock (&dateRec      , pdt);
  161.     do_get_clock (&baseDateRec, pdtmp);
  162.  
  163.     /* If the date is reasonable, subtract the days since Jan. 1, 1980 */
  164.  
  165.     if (pdtmp[0] < pdt[0])
  166.         pdt[0] -= pdtmp[0];
  167.  
  168. #ifdef DEBUG_CLOCK
  169.     printf("pdt[0] = %ld  pdt[1] = %ld\n", pdt[0], pdt[1]);
  170. #endif
  171. }
  172.  
  173.  
  174.     static void
  175. do_get_clock (DateTimeRec *dateRec, long *pdt)
  176.  
  177. {
  178.     long     idate;
  179.     static int mstart[12] =
  180.        {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334};
  181.  
  182.  
  183.     idate = (long) dateRec->year * 365 +
  184.         (dateRec->year / 4 + 1 +        /* account for leap years */
  185.          mstart[dateRec->month - 1] +    /* month is 1-origin */
  186.          dateRec->day - 1);                /* day of month is 1-origin */
  187.     if (dateRec->month <= 2 && dateRec->year % 4 == 0)        /* Jan. or Feb. of leap year */
  188.         idate--;
  189.  
  190.     pdt[0] = idate;
  191.     pdt[1] = (dateRec->hour * 60L + dateRec->minute) * 60000L + dateRec->second * 1000L;
  192. }
  193.  
  194.  
  195. /* ------ Screen management ------ */
  196.  
  197. /* Write a string to the console. */
  198.  
  199.     void
  200. gp_console_puts (const char *str, uint size)
  201.  
  202. {
  203.     extern void gp_macui_console_puts (void);
  204.  
  205.  
  206.     gp_macui_console_puts ();
  207.  
  208.     fwrite (str, 1, size, stdout);
  209. }
  210.  
  211. /* Make the console current on the screen. */
  212.  
  213.     int
  214. gp_make_console_current (gx_device *dev)
  215.  
  216. {
  217.     return 0;
  218. }
  219.  
  220. /* Make the graphics current on the screen. */
  221.  
  222.     int
  223. gp_make_graphics_current (gx_device *dev)
  224. {
  225.     return 0;
  226. }
  227.  
  228.  
  229. /* ------ Printer accessing ------ */
  230.  
  231. /* These should NEVER be called. */
  232.  
  233. /* Open a connection to a printer.  A null file name means use the */
  234. /* standard printer connected to the machine, if any. */
  235. /* "|command" opens an output pipe. */
  236. /* Return NULL if the connection could not be opened. */
  237.  
  238.     FILE *
  239. gp_open_printer (char *fname)
  240.  
  241. {    
  242.     return
  243.       (strlen (fname) == 0
  244.             ? gp_open_scratch_file (gp_scratch_file_name_prefix, fname, "wb")
  245.             : fopen (fname, "wb"));
  246. }
  247.  
  248. /* Close the connection to the printer. */
  249.  
  250.     void
  251. gp_close_printer (FILE *pfile, const char *fname)
  252.  
  253. {
  254.     fclose (pfile);
  255. }
  256.  
  257.  
  258. /* ------ File name syntax ------ */
  259.  
  260. /* Define the character used for separating file names in a list. */
  261.  
  262. const char gp_file_name_list_separator = ',';
  263.  
  264. /* Define the default scratch file name prefix. */
  265.  
  266. const char gp_scratch_file_name_prefix[] = "tempgs_";
  267.  
  268. /* Define whether case is insignificant in file names. */
  269.  
  270. const int gp_file_names_ignore_case = 1;
  271.  
  272. /* Define the string to be concatenated with the file mode */
  273. /* for opening files without end-of-line conversion. */
  274.  
  275. const char gp_fmode_binary_suffix[] = "b";
  276.  
  277. /* Define the file modes for binary reading or writing. */
  278.  
  279. const char gp_fmode_rb[] = "rb";
  280. const char gp_fmode_wb[] = "wb";
  281.  
  282.  
  283. /* Create and open a scratch file with a given name prefix. */
  284. /* Write the actual file name at fname. */
  285.  
  286.     FILE *
  287. gp_open_scratch_file (const char *prefix, char *fname, const char *mode)
  288.  
  289. {
  290.     FILE  *pFile;
  291.  
  292.  
  293.     strcpy (fname, (char *) prefix);
  294.     {
  295.         char newName[50];
  296.  
  297.  
  298.         tmpnam (newName);
  299.         strcat (fname, newName);
  300.     }
  301.  
  302.     if ((pFile = fopen (fname, mode)) /* != (FILE *) NULL */)
  303.     {
  304. #if 0
  305.         pFile->remove = 1;
  306. #endif
  307.     }
  308.  
  309.     return pFile;
  310. }
  311.  
  312.  
  313. /* Answer whether a file name contains a directory/device specification, */
  314. /* i.e. is absolute (not directory- or device-relative). */
  315.  
  316.     int
  317. gp_file_name_is_absolute (const char *fname, register uint len)
  318.  
  319. {
  320.     if (len /* > 0 */)
  321.     {
  322.         if (*fname == ':')
  323.         {
  324.             return 0;
  325.         }
  326.         else
  327.         {
  328.             register char  *p;
  329.             register char    lastWasColon;
  330.             register char    sawColon;
  331.  
  332.  
  333.             for (len, p = (char *) fname, lastWasColon = 0, sawColon = 0;
  334.                  len /* > 0 */;
  335.                  len--, p++)
  336.             {
  337.                 if (*p == ':')
  338.                 {
  339.                     sawColon = 1;
  340.  
  341.                     if (lastWasColon /* != 0 */)
  342.                     {
  343.                         return 0;
  344.                     }
  345.                     else
  346.                     {
  347.                         lastWasColon = 1;
  348.                     }
  349.                 }
  350.                 else
  351.                 {
  352.                     lastWasColon = 0;
  353.                 }
  354.             }
  355.  
  356.             return sawColon;
  357.         }
  358.     }
  359.     else
  360.     {
  361.         return 0;
  362.     }
  363. }
  364.  
  365. /* Answer the string to be used for combining a directory/device prefix */
  366. /* with a base file name.  The file name is known to not be absolute. */
  367.  
  368.     const char *
  369. gp_file_name_concat_string (const char *prefix, uint plen, const char *fname, uint len)
  370.  
  371. {
  372.     if ( plen > 0 && prefix[plen - 1] == ':' )
  373.         return "";
  374.     return ":";
  375. }
  376.  
  377.  
  378. /* ------ File operations ------ */
  379.  
  380. /* If the file given by fname exists, fill in its status and return 1; */
  381. /* otherwise return 0. */
  382.  
  383.     int
  384. gp_file_status (const char *fname, file_status *pstatus)
  385.  
  386. {
  387. #if 0
  388.     struct stat sbuf;
  389.  
  390.  
  391.     pstatus->size_pages         = (sbuf.st_size + 511L) >> 9;
  392.     pstatus->size_bytes         = sbuf.st_size;
  393.     pstatus->time_referenced = sbuf.st_mtime;
  394.     pstatus->time_created     = sbuf.st_ctime;
  395. #endif
  396.  
  397.     return 1;
  398. }
  399.  
  400.  
  401. /* ------ File enumeration ------ */
  402.  
  403. /****** THIS IS NOT SUPPORTED ON MACINTOSH SYSTEMS. ******/
  404.  
  405. struct file_enum_s {
  406.     char *pattern;
  407.     int first_time;
  408.     gs_memory_procs mprocs;
  409. };
  410.  
  411. /* Initialize an enumeration.  NEEDS WORK ON HANDLING * ? \. */
  412.  
  413.     file_enum *
  414. gp_enumerate_files_init (const char *pat, uint patlen,
  415.                          proc_alloc_t palloc, proc_free_t pfree)
  416.  
  417. {    file_enum *pfen = (file_enum *)(*palloc)(1, (size_t) sizeof(file_enum), "gp_enumerate_files");
  418.     char *pattern;
  419.     if ( pfen == 0 ) return 0;
  420.     pattern = (*palloc)(patlen + 1, (size_t) 1,
  421.                 "gp_enumerate_files(pattern)");
  422.     if ( pattern == 0 ) return 0;
  423.     memcpy(pattern, pat, patlen);
  424.     pattern[patlen] = 0;
  425.     pfen->pattern = pattern;
  426.     pfen->mprocs.alloc = palloc;
  427.     pfen->mprocs.free = pfree;
  428.     pfen->first_time = 1;
  429.     return pfen;
  430. }
  431.  
  432. /* Enumerate the next file. */
  433.  
  434.     uint
  435. gp_enumerate_files_next (file_enum *pfen, char *ptr, uint maxlen)
  436.  
  437. {    if ( pfen->first_time )
  438.        {    pfen->first_time = 0;
  439.        }
  440.     return -1;
  441. }
  442.  
  443. /* Clean up the file enumeration. */
  444.  
  445.     void
  446. gp_enumerate_files_close (file_enum *pfen)
  447.  
  448. {    proc_free_t pfree = pfen->mprocs.free;
  449.     (*pfree)(pfen->pattern, (uint) strlen(pfen->pattern) + 1, 1,
  450.          "gp_enumerate_files_close(pattern)");
  451.     (*pfree)((char *)pfen, 1, (size_t)sizeof(file_enum), "gp_enumerate_files_close");
  452. }
  453.  
  454.  
  455. static short CursorNow = 0;
  456. static short WatchVal  = 0;
  457. static short WatchPos  = 0;
  458. static long     WatchTicks;
  459. Boolean         gDoCheckInterrupts = FALSE;
  460.  
  461.  
  462. Boolean    gp_in_check_interrupts (void);
  463.  
  464.  
  465.     Boolean
  466. gp_in_check_interrupts (void)
  467.  
  468. {
  469.     return WatchVal > 1;
  470. }
  471.  
  472.  
  473.     short
  474. gp_check_interrupts (void)
  475.  
  476. {
  477.     short        retVal = FALSE;
  478.     EventRecord theEvent;
  479.     void        SetCursorType (short cursorID);
  480.  
  481.  
  482.     SystemTask ();
  483.  
  484.     if (WatchVal == 0)
  485.     {
  486.         ShowCursor ();
  487.         
  488.         if (gDoCheckInterrupts)
  489.             SetCursorType (watchCursor);
  490.         
  491.         WatchTicks = TickCount ();
  492.         WatchPos   = 0;
  493.     }
  494.     
  495.     WatchVal++;
  496.  
  497.     if (WatchVal > 0 && TickCount () - WatchTicks > 15)
  498.     {
  499.         WatchPos = (WatchPos + 1) % NUM_MAC_WATCH_CURS;
  500.  
  501.         if (gDoCheckInterrupts)
  502.             SetCursorType (128 + WatchPos);
  503.  
  504.         if (GetOSEvent (keyDownMask | autoKeyMask, &theEvent) &&
  505.             (theEvent.message & charCodeMask) == '.' &&
  506.             (theEvent.modifiers & cmdKey) /* != 0 */)
  507.         {
  508.             retVal = TRUE;
  509.         }
  510.         else
  511.         {            
  512.             if (gWNEPresent)
  513.                 (void) WaitNextEvent (0, &theEvent, 0L, (RgnHandle) NULL);
  514.         }
  515.  
  516.         WatchTicks = TickCount ();
  517.     }
  518.  
  519.     return retVal;
  520. }
  521.  
  522.  
  523. enum
  524. {
  525.     iOKOutline = OK + 1,
  526.     iStaticTextItem
  527. };
  528.  
  529.  
  530. Boolean gp_mac_alert (char *msg, short lenStr, short index);
  531.  
  532.  
  533.     Boolean
  534. gp_mac_alert (char *msg, short lenStr, short index)
  535.  
  536. {
  537.     Boolean        retVal = FALSE;
  538.     Str255        string;
  539.     StringPtr    pStr   = (StringPtr) NULL;
  540.  
  541.  
  542.     if (msg /* != (char *) NULL */)
  543.     {
  544.         if (lenStr > 255)
  545.             lenStr = 255;
  546.         string[0] = lenStr;
  547.         BlockMove ((Ptr) msg, (Ptr) &string[1], (Size) lenStr);
  548.         pStr = string;
  549.     }
  550.     else
  551.     {
  552.         if (0 < index && index < __iLastAlertStrStr__)
  553.         {
  554.             GetIndString (string, MACALERTSTRS_RES_ID, index);
  555.             pStr = string;
  556.         }
  557.     }
  558.  
  559.     if (pStr /* != (StringPtr) NULL */)
  560.     {
  561.         DialogPtr dialog = GetNewDialog (MACALERTDLOG, (char *) NULL, (WindowPtr) -1);
  562.         short      iType;
  563.         Handle      hItem;
  564.         Rect      rect;
  565.         short      item;
  566.  
  567.  
  568.         if (dialog /* != (DialogPtr) NULL */)
  569.         {
  570.             /*...Prep outline field...*/
  571.  
  572.             GetDItem (dialog, iOKOutline, &iType, &hItem, &rect);
  573.  
  574.             if (iType == userItem | itemDisable)
  575.             {
  576.                 pascal void drawOutline (WindowPtr dialog, short item);
  577.  
  578.  
  579.                 SetDItem (dialog, iOKOutline, iType, (Handle) drawOutline, &rect);
  580.             }
  581.  
  582.             ParamText (pStr, (StringPtr) NULL, (StringPtr) NULL, (StringPtr) NULL);
  583.  
  584.             ShowWindow (dialog);
  585.             InitCursor ();
  586.             ModalDialog ((ProcPtr) NULL, &item);
  587.             DisposDialog (dialog);
  588.  
  589.             retVal = TRUE;
  590.         }
  591.     }
  592.  
  593.     return retVal;
  594. }
  595.  
  596.  
  597. short gp_VMError (char *msg, short index);
  598.  
  599.  
  600.     short
  601. gp_VMError (char *msg, short index)
  602.  
  603. {
  604.     Str255    sFormat;
  605.     Boolean    fDoFPrintF;
  606.  
  607.  
  608.     GetIndString (sFormat, MACALERTSTRS_RES_ID, iCouldNotAllocateFmt);
  609.  
  610.     if (!(fDoFPrintF = ResError ()))
  611.     {
  612.         Str255    sMsg;
  613.  
  614.  
  615.         sFormat[sFormat[0] + 1] = '\0';
  616.  
  617.         GetIndString (sMsg, MACALERTSTRS_RES_ID, index);
  618.  
  619.         if (!(fDoFPrintF = ResError ()))
  620.         {
  621.             char    string[256];
  622.  
  623.  
  624.             sMsg[sMsg[0] + 1] = '\0';
  625.  
  626.             fDoFPrintF = (sprintf (string, (char *) &sFormat[1], (char *) &msg[1]) == 1) &&
  627.                          gp_mac_alert (string, strlen (string), 0);
  628.         }
  629.     }
  630.  
  631.     if (fDoFPrintF)
  632.     {
  633.         fprintf (stderr,
  634.                  "Could not allocate %s.  Please quit and increase MacGS' memory size\n",
  635.                  msg);
  636.     }
  637.  
  638.     return_error (gs_error_VMerror);
  639. }
  640.  
  641.  
  642. static Boolean        gGestaltPresent;
  643. static SysEnvRec     gEnvRec;
  644.  
  645.  
  646.     static void
  647. InitGlobals (void)
  648.  
  649. {
  650.     static Boolean    fBeenHere = FALSE;
  651.     Boolean            TrapAvailable (short trapNum);
  652.     Boolean            HasColorQD (void);
  653.     Boolean            HasSys7SFDlog (void);
  654.     Boolean            HasFindFolder (void);
  655.  
  656.  
  657.     if (!fBeenHere)
  658.     {
  659.         fBeenHere = TRUE;
  660.  
  661.         gGestaltPresent = TrapAvailable (_GestaltDispatch);
  662.         gWNEPresent        = TrapAvailable (_WaitNextEvent);
  663.  
  664.         if (!gGestaltPresent)
  665.             (void) SysEnvirons (1, &gEnvRec);
  666.  
  667.         gHasColorQD        = HasColorQD ();
  668.         gSys7SFDlog        = HasSys7SFDlog ();
  669.         gHasFindFolder    = HasFindFolder ();
  670.  
  671.         if (!gSys7SFDlog)
  672.             SetPt (&gSFWhere, 50, 50);
  673.  
  674.         GetIndString ((StringPtr) gSFFName, MACSTRS_RES_ID, iSavePictureNameStr);
  675.         (void) PtoCstr ((StringPtr) gSFFName);
  676.     }
  677. }
  678.  
  679.  
  680.     static Boolean
  681. HasColorQD (void)
  682.  
  683. {
  684.     if (gGestaltPresent)
  685.     {
  686.         long    version;
  687.         OSErr    err = Gestalt (gestaltQuickdrawVersion, &version);
  688.  
  689.  
  690.         return (err == noErr && version >= gestalt32BitQD);
  691.     }
  692.     else
  693.     {
  694.         //    pre-Gestalt method
  695.         
  696.         return gEnvRec.hasColorQD;
  697.     }
  698. }
  699.  
  700.  
  701.     static Boolean
  702. HasSys7SFDlog (void)
  703.  
  704. {
  705.     if (gGestaltPresent)
  706.     {
  707.         long    attrBits;
  708.         OSErr    err = Gestalt (gestaltStandardFileAttr, &attrBits);
  709.  
  710.  
  711.         return (err == noErr && (attrBits & (1L << gestaltStandardFile58)));
  712.     }
  713.     else
  714.     {
  715.         return FALSE;
  716.     }
  717. }
  718.  
  719.  
  720.     static Boolean
  721. HasFindFolder (void)
  722.  
  723. {
  724.     if (gGestaltPresent)
  725.     {
  726.         long    attrBits;
  727.         OSErr    err = Gestalt (gestaltFindFolderAttr, &attrBits);
  728.  
  729.  
  730.         return (err == noErr && (attrBits & (1L << gestaltFindFolderPresent)));
  731.     }
  732.     else
  733.     {
  734.         return FALSE;
  735.     }
  736. }
  737.  
  738.  
  739. /*    copied from Pascal code in Inside Mac, Volume VI, p. 3-8.    */
  740.  
  741. TrapType    GetTrapType (short trapNum);
  742. short        NumToolboxTraps (void);
  743.  
  744.  
  745.     static short
  746. NumToolboxTraps (void)
  747.  
  748. {
  749.     if (NGetTrapAddress (_InitGraf, ToolTrap) == NGetTrapAddress (0xAA6E, ToolTrap))
  750.         return 0x200;
  751.     else
  752.         return 0x400;
  753. }
  754.  
  755.  
  756.     static TrapType
  757. GetTrapType (short trapNum)
  758.  
  759. {
  760.     if ((trapNum & 0x0800) > 0)
  761.         return ToolTrap;
  762.     else
  763.         return OSTrap;
  764. }
  765.  
  766.  
  767.     static Boolean
  768. TrapAvailable (short trapNum)
  769.  
  770. {
  771.     TrapType trapType = GetTrapType (trapNum);
  772.  
  773.  
  774.     if (trapType == ToolTrap)
  775.     {
  776.         trapNum &= 0x07FF;
  777.  
  778.         if (trapNum >= NumToolboxTraps ())
  779.             trapNum = _Unimplemented;
  780.     }
  781.     
  782.     return (NGetTrapAddress (trapNum, trapType) != NGetTrapAddress (_Unimplemented, ToolTrap));
  783. }
  784.  
  785.  
  786. void    macForceCursorInit (void);
  787.  
  788.  
  789.     void
  790. macForceCursorInit (void)
  791.  
  792. {
  793.     void    DoCursorType (short cursorID);
  794.  
  795.  
  796.     DoCursorType (0);
  797.     
  798.     CursorNow = 0;
  799.     WatchVal  = 0;
  800. }
  801.  
  802.  
  803.     static void
  804. SetCursorType (short cursorID)
  805.  
  806. {
  807.     if (CursorNow == cursorID)
  808.         return;
  809.     
  810.     DoCursorType (cursorID);
  811.     
  812.     CursorNow = cursorID;
  813. }
  814.  
  815.  
  816.     static void
  817. DoCursorType (short cursorID)
  818.  
  819. {
  820.     extern void macInitCursor (void);
  821.  
  822.  
  823.     if (cursorID /* != 0 */)
  824.     {
  825.         CursHandle curs = GetCursor (cursorID);
  826.  
  827.  
  828.         SetCursor (*curs);
  829.     }
  830.     else
  831.     {
  832.         macInitCursor ();
  833.     }
  834. }
  835.  
  836.  
  837.     static pascal void
  838. drawOutline (WindowPtr dialog, short item)
  839.  
  840. {
  841.     short    iType;
  842.     Handle    hItem;
  843.     Rect    rect;
  844.     GrafPtr    savePort;
  845.  
  846.  
  847.     GetPort (&savePort);
  848.     SetPort ((GrafPtr) dialog);
  849.         GetDItem (dialog, item, &iType, &hItem, &rect);
  850.         PenSize (3, 3);
  851.         FrameRoundRect (&rect, 16, 16);
  852.     SetPort (savePort);
  853. }
  854.  
  855.  
  856.     void
  857. macInitCursor (void)
  858.  
  859. {
  860. #undef _SetCursor
  861.  
  862.  
  863.     asm
  864.     {
  865.         movea.l    (a5),a0
  866.         pea        -108(a0)            ;  arrow
  867.         _SetCursor
  868.     }
  869. }
  870.